<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Share_model extends MY_Model {
    
    protected $TB_SHARE = 'dc_share';
    protected $USER_COLS = array(
        'share_id',
        'user_id',
        'product_id',
        'share_content',
        'share_create_time',
        'share_post_id',
        'share_is_display'
    );
    
    public function __construct() {
        parent::__construct();
    }
    
    public function add_share($user_id, $product_id, $share_content, 
        $share_create_time, $share_post_id=null, $share_is_display=0) {
        $query = $this->db->query("INSERT INTO $this->TB_SHARE 
            (`user_id`, `product_id`, `share_content`, `share_create_time`, 
            `share_post_id`, `share_is_display`) VALUES 
            ('$user_id', '$product_id', '$share_content', '$share_create_time', 
            '$share_post_id', '$share_is_display')");
        return $query ? $this->db->insert_id() : false;
    }
    
    public function get_share_count_of_product($product_id) {
        return $this->db->query("SELECT `share_id` FROM `$this->TB_SHARE` 
            WHERE `product_id` = $product_id")->num_rows();
    }
    
}